using UnityEngine;

public class PlayerStateBehavior_UpDownUp : AbstractPlayerStateBehavior
{
	public static PlayerStateBehavior_UpDownUp instance;

	private PlayerStateBehavior_UpDownUp()
	{
	}

	public static PlayerStateBehavior_UpDownUp getInstance()
	{
		if (instance == null)
		{
			instance = new PlayerStateBehavior_UpDownUp();
		}
		return instance;
	}

	public override void enter(Player owner)
	{
		base.enter(owner);
		owner.LookAt(owner.getOffenseBasketPos());
		owner.getBallInHand();
		owner.updownup_is_turnaround = false;
		if (MathHelper.isInPercent(30f) || (owner.isSingleCrossOver && owner.teamType == TeamType.COMPUTER))
		{
			owner.updownup_is_turnaround = true;
			if ((owner.teamType == TeamType.COMPUTER && UIChooseTeam.comLevel >= 8) || (owner.teamType == TeamType.USER && GameData.TeamLevel[UIChooseTeam.indexInTeamData_User] >= 8))
			{
				if (MathHelper.isInPercent(50f))
				{
					owner.paraPlayer.AI.time_Stop = 1f;
					owner.playAnimation(AnimationName.player_dribble_run_turnaround, 1f, 0.8f);
				}
				else
				{
					owner.playAnimation(AnimationName.player_dribble_run_back_crossover, 0.8f, 0.8f);
					owner.paraPlayer.AI.time_Stop = 2f;
				}
			}
			else
			{
				owner.playAnimation(AnimationName.player_dribble_run_back_crossover, 0.8f, 0.8f);
				owner.paraPlayer.AI.time_Stop = 2f;
			}
			Vector3 position = owner.getPosition();
			if (position.x > 0f)
			{
				Vector3 position2 = owner.getPosition();
				if (position2.z < -11f)
				{
					owner.setMirrorAnimation();
					return;
				}
				Vector3 position3 = owner.getPosition();
				if (position3.z > 11f)
				{
					owner.setNormalAnimation();
					return;
				}
				Vector3 vector = Vector3.Cross(owner.getPosition(), owner.getParaPlayerPositon());
				if (vector.y > 0f)
				{
					owner.setNormalAnimation();
				}
				else
				{
					owner.setMirrorAnimation();
				}
				return;
			}
			Vector3 position4 = owner.getPosition();
			if (position4.z > 11f)
			{
				owner.setMirrorAnimation();
				return;
			}
			Vector3 position5 = owner.getPosition();
			if (position5.z < -11f)
			{
				owner.setNormalAnimation();
				return;
			}
			Vector3 vector2 = Vector3.Cross(owner.getPosition(), owner.getParaPlayerPositon());
			if (vector2.y > 0f)
			{
				owner.setNormalAnimation();
			}
			else
			{
				owner.setMirrorAnimation();
			}
			return;
		}
		owner.setNormalAnimation();
		switch (Random.Range(0, 3))
		{
		case 0:
			owner.playAnimation(AnimationName.player_dribble_run_crossleg, 1f, 0.8f);
			break;
		case 1:
			if (Random.Range(0, 2) == 1)
			{
				owner.setMirrorAnimation();
			}
			owner.playAnimation(AnimationName.player_dribble_run_crossleg2, 1f, 0.8f);
			break;
		default:
			owner.playAnimation(AnimationName.player_dribble_run_back, 1f, 0.8f);
			break;
		}
		if (MathHelper.isInPercent(50f) && owner.IsBeingDefense())
		{
			owner.paraPlayer.AI.do_tumble();
		}
	}

	public override void fixedUpdate(Player owner)
	{
		base.fixedUpdate(owner);
		if (owner.IsPlayingAnimation(AnimationName.player_dribble_run_turnaround))
		{
			Vector3 localScale = owner.myTransform.localScale;
			if (localScale.x > 0f)
			{
				if (owner.myAnimation[AnimationName.player_dribble_run_turnaround].normalizedTime > 0.3f && owner.myAnimation[AnimationName.player_dribble_run_turnaround].normalizedTime <= 0.6f)
				{
					GameHelper.MoveTo(owner, -owner.myTransform.right + owner.getPosition(), Global.NormalMoveSpeed_Player, isLookAtTargetPos: false);
				}
				else if (owner.myAnimation[AnimationName.player_dribble_run_turnaround].normalizedTime > 0.6f)
				{
					GameHelper.MoveTo(owner, owner.myTransform.forward + owner.getPosition(), Global.NormalMoveSpeed_Player, isLookAtTargetPos: false);
				}
			}
			else if (owner.myAnimation[AnimationName.player_dribble_run_turnaround].normalizedTime > 0.3f && owner.myAnimation[AnimationName.player_dribble_run_turnaround].normalizedTime <= 0.6f)
			{
				GameHelper.MoveTo(owner, owner.myTransform.right + owner.getPosition(), Global.NormalMoveSpeed_Player, isLookAtTargetPos: false);
			}
			else if (owner.myAnimation[AnimationName.player_dribble_run_turnaround].normalizedTime > 0.6f)
			{
				GameHelper.MoveTo(owner, owner.myTransform.forward + owner.getPosition(), Global.NormalMoveSpeed_Player, isLookAtTargetPos: false);
			}
		}
		else if (owner.IsPlayingAnimation(AnimationName.player_dribble_run_back_crossover))
		{
			Vector3 localScale2 = owner.myTransform.localScale;
			if (localScale2.x > 0f)
			{
				if (owner.myAnimation[AnimationName.player_dribble_run_back_crossover].normalizedTime > 0.6f)
				{
					GameHelper.MoveTo(owner, owner.myTransform.forward + owner.myTransform.right + owner.getPosition(), Global.NormalMoveSpeed_Player + 3f, isLookAtTargetPos: false);
				}
			}
			else if (owner.myAnimation[AnimationName.player_dribble_run_back_crossover].normalizedTime > 0.6f)
			{
				GameHelper.MoveTo(owner, owner.myTransform.forward - owner.myTransform.right + owner.getPosition(), Global.NormalMoveSpeed_Player + 3f, isLookAtTargetPos: false);
			}
		}
		if (owner.updownup_is_turnaround && (owner.myAnimation[AnimationName.player_dribble_run_turnaround].normalizedTime > 0.9f || owner.myAnimation[AnimationName.player_dribble_run_back_crossover].normalizedTime > 0.9f || !owner.IsPlayingAnimation()) && owner.teamType == TeamType.USER && !owner.isSingleCrossOver)
		{
			owner.do_dribble_stay();
		}
	}
}
